<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions"%>

<h2><fmt:message key = "form.listDepartments"/><c:out value = "${organizationName}"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<p>
   <a href = "adminui?_action=departmentForm&organization_id=${organizationId}">
     <fmt:message key = "Command.add"/>
   </a>
</p>      

<p>
<a href="adminui?_action=departmentsList&type=all&organization_id=${organizationId}">
  <fmt:message key="Command.client.all"/>
</a>

<a href="adminui?_action=departmentsList&type=active&organization_id=${organizationId}">
  <fmt:message key="Command.client.active"/>
</a>

<a href="adminui?_action=departmentsList&type=inactive&organization_id=${organizationId}">
  <fmt:message key="Command.client.inactive"/>
</a>
</p>

   <table width="100%" cellpadding="10" cellspacing="10">
      <thead>
         <tr style="border-bottom: 1px #f1f1f1 solid;">       
            <th><a class="head" href="adminui?_action=departmentsList&orderBy=N&order=${order}&type=${type}&organization_id=${organizationId}">N</a></th>
            <th><a class="head" href="adminui?_action=departmentsList&orderBy=name&order=${order}&type=${type}&organization_id=${organizationId}"><fmt:message key = "department.name"/></a></th>            
            <th><fmt:message key = "department.operations"/></th>            
         </tr>
      </thead>

      <tbody>                 
         <c:forEach var = "department" items = "${departmentsList}">
            <tr style="border-bottom: 1px #f1f1f1 solid;">
               <td>${department.id}</td>
               <td><c:out value="${department.name}"/></td>                              
               <td>
                        <a class = "control" href = 'adminui?_action=departmentForm&department_id=${department.id}&organization_id=${organizationId}'>
                           <fmt:message key = "client.operations.edit"/>
                        </a>                   
                      <c:choose>
                         <c:when test="${department.status == 'active'}">                     
                            <a class = "control" href = "adminui?_action=setDepartmentStatus&status=delete&orderBy=${orderBy}&order=${order}&type=${type}&department_id=${department.id}&organization_id=${organizationId}">
                              <fmt:message key = "client.operations.remove"/>
                            </a>                      
                          </c:when>
                          <c:otherwise>
                            <a class = "control" href = "adminui?_action=setDepartmentStatus&status=restore&orderBy=${orderBy}&order=${order}&type=${type}&department_id=${department.id}&organization_id=${organizationId}">
                              <fmt:message key = "client.operations.restore"/>
                            </a>
                          </c:otherwise>     
                      </c:choose>  
               </td>	
            </tr>
         </c:forEach>
         
      <c:if test="${fn:length(departmentsList) == 0}">      
        <tr><td colspan="3" align="center"><fmt:message key="emptyList"/></td></tr>
      </c:if> 
           
      </tbody>
   </table>
  
   <p>
     <a class = "control" href = "adminui?_action=departmentForm&organization_id=${organizationId}">
       <fmt:message key = "Command.add"/>
     </a>
   </p>   